package com.surekam.dma.service.dma.dms;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;

import com.surekam.dma.dao.dma.dms.DocumentDao;
import com.surekam.dma.entity.dma.dms.Document;
//Spring Bean的标识.
@Component
//默认将类中的所有函数纳入事务管理.
@Transactional
public class DocumentManager {
	private static Logger logger=LoggerFactory.getLogger(DocumentManager.class);
	private DocumentDao documentDao;
	/**
	 * 使用属性过滤条件查询用户.
	 */
	@Transactional(readOnly = true)
	public Page<Document> searchDoc(final Page<Document> page,final List<PropertyFilter> filters) {
		return documentDao.findPage(page, filters);
	}
	/**
	 * 根据文件名进行查询
	 */
	@Transactional(readOnly = true)
	public Document findDocByFileName(String fileName){
		return documentDao.findUniqueBy("fileName", fileName);
	}
	/**
	 * 根据创建者进行查询
	 */
	@Transactional(readOnly = true)
	public Document findDocByUserName(String userName){
		return documentDao.findUniqueBy("userName", userName);
	}
	/**
	 * 根据id进行查询
	 */
	public Document getDoc(Long id){
		return documentDao.get(id);
	}
	/**
	 * 删除文档
	 */
	public void deleteDoc(Long id){
		logger.warn("删除文档"+id,SpringSecurityUtils.getCurrentUserName());
		documentDao.delete(id);
	}
	/**
	 * 编辑文档
	 */
	public void saveDoc(Document entity){
		documentDao.save(entity);
	}
	/**
	 * 查询全部文档
	 */
	//-- Authority Manager --//
	@Transactional(readOnly = true)
	public List<Document> getAllDoc(){
		return documentDao.getAll();
	}
	@Autowired
	public void setDocDao(DocumentDao docDao) {
		this.documentDao = docDao;
	}
	
}
